package com.sporadic.desk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sporadic.desk.dao.DishesDao;
import com.sporadic.desk.pojo.Dishes;
import com.sporadic.desk.pojo.Menu;
import com.sporadic.desk.service.DishesService;
import com.sporadic.desk.service.MenuService;
import dto.DishesDTO;
import org.apache.ibatis.annotations.CacheNamespace;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: sporadic
 * @description:
 * @author: LHD   QQ:1727865856
 * @create: 2019-10-22 08:55
 **/
@Service
public class DishesServiceImpl extends ServiceImpl<DishesDao, Dishes>
        implements DishesService {

    @Autowired
    private MenuService menuService;
    @Autowired
    private DishesDao dishesDao;

    @Override
    public List<DishesDTO> queryDishes(Integer mId, Integer menuId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("dishes_merchant", mId);
        //如果菜单id等于0说明是查询全部MybatisCache
        List<Integer> list = menuService.queryTab(menuId, mId);
        if (!list.isEmpty()) {
            queryWrapper.in("dishes_typeId", list);
        }
        List<DishesDTO> dishesDTOList=new ArrayList<>();
        list(queryWrapper).forEach(dishes->{
            DishesDTO dishesDTO=new DishesDTO();
            BeanUtils.copyProperties(dishes,dishesDTO);
            dishesDTOList.add(dishesDTO);
        });

        return dishesDTOList;
    }

    @Override
    public List<DishesDTO> selectByorderId(String orderId) {
        List<Dishes> dishes = dishesDao.selectByOrderId(orderId);
        List<DishesDTO> dishesDTOList = new ArrayList<>();
        dishes.forEach(goods -> {
            DishesDTO dishesDTO = new DishesDTO();
            BeanUtils.copyProperties(goods, dishesDTO);
            dishesDTOList.add(dishesDTO);
        });
        return dishesDTOList;
    }
}
